define(['jquery', 'bootstrap', 'backend', 'table', 'form', 'template'], function ($, undefined, Backend, Table, Form, Template) {
    var Controller = {
        index: function () {
            // 初始化表格参数配置
            Table.api.init({
                extend: {
                    index_url: '/sys/job/data?dept_id=' + dept_id,
                    add_url: '/sys/job/add',
                    edit_url: '/sys/job/edit',
                    del_url: '/sys/job/del',
                    multi_url: 'data/multi.json',
                    "table": 'page',
                }
            });
            var table = $("#table");
            // 初始化表格
            table.bootstrapTable({
                url: $.fn.bootstrapTable.defaults.extend.index_url,
                sortName: 'id',
                columns: [
                    [
                        {field: 'aaa', checkbox: true},
                        {field: 'id',  title: __('id'), operate: false},
                        {field: 'name', title: __('职位名称'), operate: false},
                        {field: 'des', title: __('描述'), operate: false},
                        {field: 'dept_id', title: __('部门ID'), visible: false, operate: true},
                        {field: 'dept_name', title: __('部门'), operate: false},
                        {field: 'create_time', title: __('create_time'), formatter: Table.api.formatter.datetime, operate: 'BETWEEN', type: 'datetime', addclass: 'datetimepicker', data: 'data-date-format="YYYY-MM-DD"'},
                        {field: 'update_time', title: __('update_time'), formatter: Table.api.formatter.datetime, operate: false},

                        {
                            field: 'opearte',
                            title: __('操作'),
                            operate: false,
                            formatter: function (value, row, index) {
                                return '<span class="btn btn-auth bg-blue btn-xs btn-detail">查看下面的员工</span>' + Table.api.formatter.operate(value, row, index, $("#table"));
                            },
                            events: $.extend({
                                'click .btn-auth': function (e, value, row, index) {
                                    Backend.api.open("/sys/emp/index?job_id=" + row['id'], "查看<code>" + row.name + "</code>下面的员工");

                                }
                            }, Table.api.events.operate)
                        },
                    ]
                ],
                //禁用默认搜索
                search: false,
                //启用普通表单搜索
                commonSearch: true,
                //可以控制是否默认显示搜索单表,false则隐藏,默认为false
                searchFormVisible: true,
                exportDataType: 'selected'
            });
            // 为表格绑定事件
            Table.api.bindevent(table);
            $("input[name=job_id]").attr("readonly", true);
            $("input[name=job_id]").attr("type", "hidden");
        },
        add: function () {
            Controller.api.bindevent();
        },
        edit: function () {
            Controller.api.bindevent();
        },
        api: {
            bindevent: function () {
                Form.api.bindevent($("form[role=form]"));
            }
        }
    };
    return Controller;
});